package com.mapbar.pay.action;

import com.mapbar.pay.service.UserService;
import com.mapbar.pay.util.Util;
import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;

/**
 * @date  2010-3-4  17:33:39
 * @author fengbj
 */
public class LogonAction extends BaseAction{

    public Logger logger = Logger.getLogger(this.getClass());//日志对象
    private UserService userService;
    private String userName;
    private String pwd;

    @Override
    public String execute() throws Exception {

            if(userName == null || pwd == null){
                this.addActionError("用户名或者密码不能为空");
                return "index";
            }else{
                setUser(userService.logon(userName, pwd));
                if(getUser() == null){
                    //登录失败
                    this.addActionError("用户名或者密码错误");
                    return "index";
                }else{
                    //登录成功
                    logger.info("用户登录成功！[" + getUser() + "]");
                   //写cookie
                   Util.addLogonCookie(getUser(), "30" , ServletActionContext.getResponse());

                    return SUCCESS;
                }
            }
            
            
        
    }

    public UserService getUserService() {
        return userService;
    }

    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    


}
